package org.electrical.controller.functionality;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.electrical.dao.EleGoodsDao;
import org.electrical.pojo.EleGoods;
import org.electrical.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods")
@CrossOrigin(value = "*")
public class EleGoodsController {

    @Autowired
    private EleGoodsDao eleGoodsDao;

    @RequestMapping("list")
    @ResponseBody
    public ResponseResult<List<EleGoods>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, EleGoods condition) {

        Page<EleGoods> pager = PageHelper.startPage(page, limit);
        List<EleGoods> list = eleGoodsDao.getConditionList(condition);
        return new ResponseResult(pager.getTotal(), list);

    }
}
